<html>
<head><meta charset="utf-8"><title>profiling code usage · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html">profiling code usage</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203084482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203084482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203084482">(Jul 07 2020 at 09:51)</a>:</h4>
<p>So <span class="user-mention" data-user-id="133169">@matklad</span> and I have been exploring the code usage in rust-analyzer due to salsa. We've found some curious results that we don't understand. I was thinking that what would be really useful is if we had something akin to <code>-Zself-profile</code> which would do the following:</p>
<ul>
<li>print out every monomorphized instance (along with its type parameters) and the size of its associated LLVM code</li>
<li>instrument the "collector" so that we also print out graph edges showing <strong>why</strong> each monomorphized instance was created (ideally, all the graph edges)</li>
</ul>
<p>cc <span class="user-mention" data-user-id="125250">@Wesley Wiser</span>, <span class="user-mention" data-user-id="116015">@Alex Crichton</span>, <span class="user-mention" data-user-id="120989">@njn</span> and <span class="user-mention" data-user-id="119009">@eddyb</span> as folks I thought might either have ideas of tooling to use for this or be interested in this. (I feel like I've seen some people talk about similar tooling at some point or another...)</p>



<a name="203089390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203089390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203089390">(Jul 07 2020 at 11:07)</a>:</h4>
<p>Would such a thing be helpful for determining “this bit of source code is the one that makes compiling my async code so slow” and/or “what’s taking up all the space on my tiny development board”?</p>



<a name="203093070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203093070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203093070">(Jul 07 2020 at 11:58)</a>:</h4>
<p>Link to curious results: <a href="https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/benchmarking/near/202989701">https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/benchmarking/near/202989701</a> (note that this needs quite a bit of context about salsa to really dig into unfortunatelly)</p>



<a name="203097445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203097445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203097445">(Jul 07 2020 at 12:50)</a>:</h4>
<p>is the mono item <code>size_estimate</code> interesting ? it could be added to the partitioning's existing <code>-Z print-mono-items</code> output (I realize this only applies to sizes and not printing the mono item graph w/ edges) edit: ah there's already another partitioning debug dump which prints this estimated size (but requires debug assertions)</p>



<a name="203100375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203100375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203100375">(Jul 07 2020 at 13:18)</a>:</h4>
<p>I’d also be interested in helping with something like this.</p>



<a name="203102228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203102228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203102228">(Jul 07 2020 at 13:32)</a>:</h4>
<p><span class="user-mention" data-user-id="116107">@davidtwco</span> it'd show very clearly where polymorphization helps :)</p>



<a name="203102324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203102324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203102324">(Jul 07 2020 at 13:33)</a>:</h4>
<p>Hence my interest <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span></p>



<a name="203102513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203102513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203102513">(Jul 07 2020 at 13:34)</a>:</h4>
<p>(especially with a .diff like the mir-opt tests)</p>



<a name="203104991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203104991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203104991">(Jul 07 2020 at 13:52)</a>:</h4>
<p>I've got a tool from awhile back which will say "this function generated this much LLVM IR", summed up across all monomorphizations across all codegen units, but it doesn't tell you much as to why</p>



<a name="203105026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203105026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203105026">(Jul 07 2020 at 13:53)</a>:</h4>
<p>it sounds like y'all are more interested in the graph respects of monomorphization?</p>



<a name="203105084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203105084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203105084">(Jul 07 2020 at 13:53)</a>:</h4>
<p>although one thing I also did was process my results with twiggy which has support for showing "dominators", which is akin to "this function is solely responsible for pulling in all these other functions"</p>



<a name="203105141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203105141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203105141">(Jul 07 2020 at 13:54)</a>:</h4>
<p>I can try to share the tool if it'd help</p>



<a name="203105576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203105576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203105576">(Jul 07 2020 at 13:56)</a>:</h4>
<p>similar to <a href="https://github.com/dtolnay/cargo-llvm-lines/">https://github.com/dtolnay/cargo-llvm-lines/</a> ?</p>



<a name="203106083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203106083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203106083">(Jul 07 2020 at 14:01)</a>:</h4>
<p>similar in spirit yeah, but different in implementation</p>



<a name="203116735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203116735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203116735">(Jul 07 2020 at 15:20)</a>:</h4>
<p>(just dumping the mono item graph as a dot file <em>may</em> be hard to read) <a href="/user_uploads/4715/ougdb5R-ZuKzJs6-WXpBwSBc/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/ougdb5R-ZuKzJs6-WXpBwSBc/image.png" title="image.png"><img src="/user_uploads/4715/ougdb5R-ZuKzJs6-WXpBwSBc/image.png"></a></div>



<a name="203118153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203118153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203118153">(Jul 07 2020 at 15:30)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> what is that from?</p>



<a name="203118379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203118379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203118379">(Jul 07 2020 at 15:31)</a>:</h4>
<p>just messing around trying to see what the collector's InliningMap looks like on a simple example</p>



<a name="203119944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203119944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203119944">(Jul 07 2020 at 15:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116113">lqd</span> <a href="#narrow/stream/131828-t-compiler/topic/profiling.20code.20usage/near/203097445">said</a>:</p>
<blockquote>
<p>edit: ah there's already another partitioning debug dump which prints this estimated size (but requires debug assertions)</p>
</blockquote>
<p>Just so everyone knows, if you do <code>RUSTC_LOG=rustc_mir::monomorphize::partitioning</code>, you can see the cgu partitioning initially, after merging small cgus and after inlining items: </p>
<div class="codehilite"><pre><span></span><code>wesley@endurance:~/code/rust/rust2&gt; RUSTC_LOG=rustc_mir::monomorphize::partitioning rustc +stage1-3 test.rs --crate-type=lib
warning: unused import: `std::mem`
 --&gt; test.rs:2:5
  |
2 | use std::mem;
  |     ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

[DEBUG rustc_mir::monomorphize::partitioning] INITIAL PARTITIONING:
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit 3vrhl32f903ey4ju estimated size 5 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::drop_in_place[0]&lt;alloc::vec[0]::Vec[0]&lt;u8&gt;&gt; [(External, Default)] [h04e46ad5d014fca5E] estimated size 1
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::drop_in_place[0]&lt;test::Foo[0]&gt; [(External, Default)] [h45211b5884ae8842E] estimated size 1
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::drop_in_place[0]&lt;alloc::vec[0]::Vec[0]&lt;i32&gt;&gt; [(External, Default)] [h1994aa6a797dfedeE] estimated size 1
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::drop_in_place[0]&lt;alloc::string[0]::String[0]&gt; [(External, Default)] [h7b8cb49732066e57E] estimated size 0
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::drop_in_place[0]&lt;alloc::raw_vec[0]::RawVec[0]&lt;i32, alloc::alloc[0]::Global[0]&gt;&gt; [(External, Default)] [h8f8d2d9651824446E] estimated size 1
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::drop_in_place[0]&lt;alloc::raw_vec[0]::RawVec[0]&lt;u8, alloc::alloc[0]::Global[0]&gt;&gt; [(External, Default)] [h07bee7e7ce249bc1E] estimated size 1
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit 5f2o87rkvt82sxc5 estimated size 40 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn test::{{impl}}[0]::match_to_static[0] [(External, Default)] [h86e2e606b018f385E] estimated size 40
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit 3kgi2eircqwriiff estimated size 34 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::slice_from_raw_parts_mut[0]&lt;u8&gt; [(External, Default)] [hb3fb6e51c4d38181E] estimated size 17
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::slice_from_raw_parts_mut[0]&lt;i32&gt; [(External, Default)] [hfc1b3eb34b0b8f76E] estimated size 17
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit mf27uel3gr4l5my estimated size 150 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::raw_vec[0]::{{impl}}[3]::drop[0]&lt;u8, alloc::alloc[0]::Global[0]&gt; [(External, Default)] [hc9dd369ebb51c4ceE] estimated size 22
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::raw_vec[0]::{{impl}}[3]::drop[0]&lt;i32, alloc::alloc[0]::Global[0]&gt; [(External, Default)] [h51a9f0bb0c6fe880E] estimated size 22
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::raw_vec[0]::{{impl}}[1]::ptr[0]&lt;u8, alloc::alloc[0]::Global[0]&gt; [(External, Default)] [h0e3656790a928383E] estimated size 3
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::raw_vec[0]::{{impl}}[1]::current_memory[0]&lt;u8, alloc::alloc[0]::Global[0]&gt; [(External, Default)] [hf09d821d6f8d39cbE] estimated size 50
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::raw_vec[0]::{{impl}}[1]::ptr[0]&lt;i32, alloc::alloc[0]::Global[0]&gt; [(External, Default)] [hc163c5274950be47E] estimated size 3
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::raw_vec[0]::{{impl}}[1]::current_memory[0]&lt;i32, alloc::alloc[0]::Global[0]&gt; [(External, Default)] [hd93a9acdc8155e74E] estimated size 50
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit 3x5xiqw127bb07ye estimated size 30 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::alloc[0]::{{impl}}[0]::dealloc[0] [(External, Hidden)] [h2a2d5166e492dd34E] estimated size 17
[DEBUG rustc_mir::monomorphize::partitioning]  - fn alloc::alloc[0]::dealloc[0] [(External, Hidden)] [h9d208879dcf5db14E] estimated size 13
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit eputs5eg4igd22g estimated size 40 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::unique[0]::{{impl}}[3]::as_ptr[0]&lt;i32&gt; [(External, Default)] [h99e00e7efc0a1854E] estimated size 4
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::unique[0]::{{impl}}[3]::new_unchecked[0]&lt;u8&gt; [(External, Default)] [hddba8130d82c2489E] estimated size 13
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::unique[0]::{{impl}}[3]::cast[0]&lt;u8, u8&gt; [(External, Default)] [h2de7333e774c2877E] estimated size 8
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::unique[0]::{{impl}}[3]::as_ptr[0]&lt;u8&gt; [(External, Default)] [h1ee3983e6af09b15E] estimated size 4
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::unique[0]::{{impl}}[3]::cast[0]&lt;i32, u8&gt; [(External, Default)] [hfaa80e91b6f75308E] estimated size 8
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::convert[0]::{{impl}}[3]::into[0]&lt;core::ptr[0]::unique[0]::Unique[0]&lt;u8&gt;, core::ptr[0]::non_null[0]::NonNull[0]&lt;u8&gt;&gt; [(External, Default)] [h6ef1f8b2dd6d2cfdE] estimated size 3
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] POST MERGING:
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit test.3a1fbbbh-cgu.0 estimated size 18 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::mut_ptr[0]::{{impl}}[0]::is_null[0]&lt;i32&gt; [(External, Default)] [h34bb84bb2069daa6E] estimated size 9
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::mut_ptr[0]::{{impl}}[0]::is_null[0]&lt;u8&gt; [(External, Default)] [h4ffff520fa537771E] estimated size 9
[DEBUG rustc_mir::monomorphize::partitioning]
[DEBUG rustc_mir::monomorphize::partitioning] CodegenUnit test.3a1fbbbh-cgu.1 estimated size 19 :
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::non_null[0]::{{impl}}[3]::as_ptr[0]&lt;u8&gt; [(External, Default)] [had92c948a937b33bE] estimated size 4
[DEBUG rustc_mir::monomorphize::partitioning]  - fn core::ptr[0]::non_null[0]::{{impl}}[16]::from[0]&lt;u8&gt; [(External, Default)] [h4802c4dd8caf26d8E] estimated size 5

(More content...)
</code></pre></div>



<a name="203120158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203120158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203120158">(Jul 07 2020 at 15:45)</a>:</h4>
<p>A tool like that would be really helpful for <a class="stream" data-stream-id="241847" href="/#narrow/stream/241847-t-compiler.2Fwg-incr-comp">#t-compiler/wg-incr-comp</a></p>



<a name="203123023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203123023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203123023">(Jul 07 2020 at 16:06)</a>:</h4>
<p><span class="user-mention" data-user-id="125250">@Wesley Wiser</span> would it be interesting to improve <code>-Z print-mono-items</code> to be closer to the log output ? (or is that still too abstracted away from llvm codegen statistics)</p>



<a name="203123508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203123508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203123508">(Jul 07 2020 at 16:08)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> I think the <code>.diff</code> idea you mentioned would actually be really useful. I was trying to figure out which step was bringing in items and I was basically just manually pasting the output of each stage into my diff tool which was really tedious.</p>



<a name="203127031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203127031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203127031">(Jul 07 2020 at 16:33)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> I suspect that a graph like that, hard to read or not, would be useful for the kind of detective work that <span class="user-mention" data-user-id="133169">@matklad</span> was doing</p>



<a name="203127048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203127048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203127048">(Jul 07 2020 at 16:33)</a>:</h4>
<p>though really the <em>graph</em> rendering is not that imporant</p>



<a name="203127102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203127102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203127102">(Jul 07 2020 at 16:34)</a>:</h4>
<p>as just having the list of "reasons this bit of code was instantiated"</p>



<a name="203127125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203127125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203127125">(Jul 07 2020 at 16:34)</a>:</h4>
<p>i.e., a text format may be easier to consume</p>



<a name="203127977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203127977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203127977">(Jul 07 2020 at 16:40)</a>:</h4>
<p>yes that's what I was suggesting with this excerpt of an already big graph :) i.e. that even just having the edges as text format would probably be useful already (and this was what I was trying, before attempting to visualize the graph) I'll keep at it. Visibility/stats in this area of the compiler seems to be at the crossing of many use cases, and I'm sure <span class="user-mention" data-user-id="116107">@davidtwco</span> and I can make some progress on that front</p>



<a name="203128682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203128682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203128682">(Jul 07 2020 at 16:46)</a>:</h4>
<p>In the interest of cross-references, this is an issue I've opened on cargo llvm-lines: <a href="https://github.com/dtolnay/cargo-llvm-lines/issues/25">https://github.com/dtolnay/cargo-llvm-lines/issues/25</a></p>



<a name="203215005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203215005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203215005">(Jul 07 2020 at 23:17)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> In the issue you wrote "if you have a generic fn&lt;T&gt; foo() function in crate A, and use it in crates B and C, you compile it twice." Once you know that, what do you do? Just restructure the code to avoid it?</p>



<a name="203215185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203215185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203215185">(Jul 07 2020 at 23:20)</a>:</h4>
<p>Also, just before that you said "the biggest win comes from noticing things that are monomorphised in the wrong crate". What exactly does "wrong" mean here? Like, you didn't realize the code was structured this way? Or rustc is doing something wrong?</p>



<a name="203217688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203217688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203217688">(Jul 07 2020 at 23:57)</a>:</h4>
<p><a href="https://gist.github.com/lqd/23cb5ffd286eb4bff2a8758bf7479b65">https://gist.github.com/lqd/23cb5ffd286eb4bff2a8758bf7479b65</a> is an example of what I had as a slight modification of <code>-Z print-mono-items</code> with the added estimated size and mono item graph edges (the list of accessor items, per accessed item), whereas it currently looks like <a href="https://gist.github.com/lqd/2966f52162149d744a100871df1a1dcf">https://gist.github.com/lqd/2966f52162149d744a100871df1a1dcf</a> (for 2 crates with a single generic function each, doing a println, monomorphized over 5 types or so)</p>



<a name="203246106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203246106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203246106">(Jul 08 2020 at 09:11)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> yup, basically "Just restructure the code to avoid it?", where "Just" might be pretty  involved.</p>
<blockquote>
<p>What exactly does "wrong" mean here? Like, you didn't realize the code was structured this way? </p>
</blockquote>
<p>Both. </p>
<p>Sometimes you expected the bulk of codegen happen in the upstream crate, but it happens in the downstream crates, because there's some genricness that you've missed.</p>
<p>However in the case of salsa, it might also be that rustc is doing something wrong. At least <span class="user-mention silent" data-user-id="116009">nikomatsakis</span> convinced me that a change that brought 5x llvm-lines shouldn't be necessary: <a href="https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/benchmarking/near/203015044">https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/benchmarking/near/203015044</a></p>



<a name="203248207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203248207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203248207">(Jul 08 2020 at 09:41)</a>:</h4>
<p>@matklad: I can't access that salsa Zulip. Does it require a different account?</p>



<a name="203248688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203248688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203248688">(Jul 08 2020 at 09:48)</a>:</h4>
<p>Every Zulip on <a href="http://zulipchat.com">zulipchat.com</a> (the Zulip instances hosted by the Zulip developers) is a different account - it's just like Slack instances.</p>



<a name="203252535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203252535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203252535">(Jul 08 2020 at 10:37)</a>:</h4>
<p>I'm a bit confused by the "wrong crates" and monorphizations when the example involves no generics, but a 5x change in llvm-lines provides a clear before and after to analyze</p>



<a name="203310282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203310282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203310282">(Jul 08 2020 at 19:19)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> 5x is impressive, and definitely worth investigating.</p>



<a name="203310308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203310308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203310308">(Jul 08 2020 at 19:19)</a>:</h4>
<p>I would love it if we found out that rustc was doing something really dumb that could be easily fixed :)</p>



<a name="203328585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203328585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203328585">(Jul 08 2020 at 21:54)</a>:</h4>
<p>agreed :)</p>



<a name="203403177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/profiling%20code%20usage/near/203403177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> anp <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/profiling.20code.20usage.html#203403177">(Jul 09 2020 at 15:48)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="304321">@Yifei Teng</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>